<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
// var newscript=document.createElement('script');
// newscript.src='https://sp0.baidu.com/su?wd=Java&cb=foo';
// document.body.appendChild(newscript);
// function foo(data) { //callback函数要绑定在window对象上
//    console.log(data);
// }
    let newscript = document.createElement('script')
    newscript.src= '接口地址'
    document.body.appendChild(newscript)
    function foo(data){
      console.log(data) //data实在window上的
    }
  </script>
</body>
</html>